﻿Imports MeoTom.Core.DAL

Namespace BLL
    Public Class PublicUploads
        Private _uploadId As String
        Private _uploadName As String
        Private _createDate As DateTime
        Private _status As Boolean
        Private _uploadBy As String
        Private _addedByIp As String
        Private _totalRecord As Integer
        Private _orderBy As String

        Public Property OrderBy() As String
            Get
                Return _OrderBy
            End Get
            Set(ByVal value As String)
                _OrderBy = value
            End Set
        End Property

        Public Property TotalRecord() As Integer
            Get
                Return _TotalRecord
            End Get
            Set(ByVal value As Integer)
                _TotalRecord = value
            End Set
        End Property

        Public Property UploadId() As String
            Get
                Return _UploadID
            End Get
            Set(ByVal value As String)
                _UploadID = value
            End Set
        End Property

        Public Property UploadName() As String
            Get
                Return _UploadName
            End Get
            Set(ByVal value As String)
                _UploadName = value
            End Set
        End Property

        Public Property CreateDate() As DateTime
            Get
                Return _CreateDate
            End Get
            Set(ByVal value As DateTime)
                _CreateDate = value
            End Set
        End Property

        Public Property Status() As Boolean
            Get
                Return _Status
            End Get
            Set(ByVal value As Boolean)
                _Status = value
            End Set
        End Property

        Public Property UploadBy() As String
            Get
                Return _UploadBy
            End Get
            Set(ByVal value As String)
                _UploadBy = value
            End Set
        End Property

        Public Property AddedByIp() As String
            Get
                Return _AddedByIP
            End Get
            Set(ByVal value As String)
                _AddedByIP = value
            End Set
        End Property

        Private ReadOnly _objPUpload As PublicUploadProvider

        Public Sub New()
            _objPUpload = New PublicUploadProvider()
        End Sub

        Public Function GetUpload() As DataSet
            Return _objPUpload.GetUpload(Me)
        End Function

        Public Sub UpdateUpload()
            _objPUpload.UpdateUpload(Me)
        End Sub

        Public Function DeleteUpload() As String
            Dim strReturn As String = ""
            Dim reader As SqlClient.SqlDataReader = _objPUpload.GetByID(Me)
            If reader.Read Then
                UploadID = reader("UploadID").ToString
                UploadName = reader("UploadName").ToString
                CreateDate = DateTime.Parse(reader("CreateDate").ToString)
                UploadBy = reader("UploadBy").ToString

                strReturn = UploadBy & "\" & CreateDate.Year.ToString & "\" & Right("0" & CreateDate.Month.ToString, 2) & "\" & Right("0" & CreateDate.Day.ToString, 2) & "\130x0__" & UploadName
                strReturn = strReturn & "|" & UploadBy & "\" & CreateDate.Year.ToString & "\" & Right("0" & CreateDate.Month.ToString, 2) & "\" & Right("0" & CreateDate.Day.ToString, 2) & "\100x0__" & UploadName
                strReturn = strReturn & "|" & UploadBy & "\" & CreateDate.Year.ToString & "\" & Right("0" & CreateDate.Month.ToString, 2) & "\" & Right("0" & CreateDate.Day.ToString, 2) & "\475x0__" & UploadName
                strReturn = strReturn & "|" & UploadBy & "\" & CreateDate.Year.ToString & "\" & Right("0" & CreateDate.Month.ToString, 2) & "\" & Right("0" & CreateDate.Day.ToString, 2) & "\800x0__" & UploadName
                strReturn = strReturn & "|" & UploadBy & "\" & CreateDate.Year.ToString & "\" & Right("0" & CreateDate.Month.ToString, 2) & "\" & Right("0" & CreateDate.Day.ToString, 2) & "\" & UploadName & "|"

                _objPUpload.DeleteUpload(Me)
            Else
                strReturn = "No Image Selected"
            End If
            reader.Close()
            Return strReturn
        End Function
    End Class
End Namespace